package o;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

class bnn extends cfq {
    private static bnn ˊ;
    private Context ˏ;
    private SQLiteDatabase ॱ = null;

    protected bnn(Context context) {
        super(context, "download.db", null, bnm.ˊ());
        this.ˏ = context;
        this.ॱ = getWritableDatabase();
    }

    public static synchronized bnn ˎ() {
        bnn o_bnn;
        synchronized (bnn.class) {
            if (ˊ == null) {
                ˊ = new bnn(bnl.ˏ().ॱ());
            }
            o_bnn = ˊ;
        }
        return o_bnn;
    }

    protected void ॱ(SQLiteDatabase sQLiteDatabase, int i) {
        try {
            this.ॱ = sQLiteDatabase;
            bnm o_bnm = new bnm(this, this.ˏ);
            sQLiteDatabase.beginTransaction();
            o_bnm.ॱ();
            if (i != -1) {
                sQLiteDatabase.setVersion(i);
            }
            sQLiteDatabase.setTransactionSuccessful();
        } catch (Throwable e) {
            bnc.ˎ.ˊ("DownloadDbHelper", "DownloadDbHelper initTables error. RuntimeException= ", e);
        } finally {
            sQLiteDatabase.endTransaction();
        }
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public boolean ॱ(java.lang.String r10) throws android.database.SQLException {
        /*
        r9 = this;
        r2 = 1;
        r0 = 0;
        r1 = r9.ʻ(r10);
        if (r1 != 0) goto L_0x000e;
    L_0x0008:
        r0 = new android.database.SQLException;
        r0.<init>();
        throw r0;
    L_0x000e:
        if (r10 != 0) goto L_0x0011;
    L_0x0010:
        return r0;
    L_0x0011:
        r1 = 0;
        r3 = "select count(1) as c from sqlite_master where type ='table' and name = ?";
        r4 = r9.ॱ;	 Catch:{ SQLException -> 0x0038, all -> 0x004c }
        r5 = 1;
        r5 = new java.lang.String[r5];	 Catch:{ SQLException -> 0x0038, all -> 0x004c }
        r6 = 0;
        r7 = r10.trim();	 Catch:{ SQLException -> 0x0038, all -> 0x004c }
        r5[r6] = r7;	 Catch:{ SQLException -> 0x0038, all -> 0x004c }
        r1 = r4.rawQuery(r3, r5);	 Catch:{ SQLException -> 0x0038, all -> 0x004c }
        r3 = r1.moveToNext();	 Catch:{ SQLException -> 0x004e, all -> 0x004c }
        if (r3 == 0) goto L_0x0032;
    L_0x002a:
        r3 = 0;
        r3 = r1.getInt(r3);	 Catch:{ SQLException -> 0x004e, all -> 0x004c }
        if (r3 <= 0) goto L_0x0032;
    L_0x0031:
        r0 = r2;
    L_0x0032:
        if (r1 == 0) goto L_0x0010;
    L_0x0034:
        r1.close();
        goto L_0x0010;
    L_0x0038:
        r0 = move-exception;
        r0 = r1;
    L_0x003a:
        r1 = new android.database.SQLException;	 Catch:{ all -> 0x0042 }
        r2 = "isTableExist SQLException";
        r1.<init>(r2);	 Catch:{ all -> 0x0042 }
        throw r1;	 Catch:{ all -> 0x0042 }
    L_0x0042:
        r1 = move-exception;
        r8 = r1;
        r1 = r0;
        r0 = r8;
    L_0x0046:
        if (r1 == 0) goto L_0x004b;
    L_0x0048:
        r1.close();
    L_0x004b:
        throw r0;
    L_0x004c:
        r0 = move-exception;
        goto L_0x0046;
    L_0x004e:
        r0 = move-exception;
        r0 = r1;
        goto L_0x003a;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.bnn.ॱ(java.lang.String):boolean");
    }

    public void ˋ(String str) throws SQLException {
        if (ʻ(str)) {
            try {
                this.ॱ.execSQL(" ALTER TABLE " + str + " RENAME TO _temp_" + str);
                return;
            } catch (SQLException e) {
                bnc.ˎ.ˊ("DownloadDbHelper", "alter table error!");
                throw new SQLException("alter table error!");
            }
        }
        throw new SQLException();
    }

    public void ˊ(String str) throws SQLException {
        ˏ("_temp_" + str);
    }

    public void ˏ(String str) throws SQLException {
        if (ʻ(str)) {
            ˎ(" DROP TABLE " + str);
            return;
        }
        throw new SQLException();
    }

    public void ˎ(String str) throws SQLException {
        try {
            this.ॱ.execSQL(str);
        } catch (SQLException e) {
            bnc.ˎ.ˊ("DownloadDbHelper", "DownloadDbHelper executeSQL error ] ");
            throw new SQLException("DownloadDbHelper executeSQL error ] ");
        }
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public java.lang.String[] ॱॱ(java.lang.String r6) throws android.database.SQLException {
        /*
        r5 = this;
        r0 = 0;
        r1 = r5.ʻ(r6);
        if (r1 != 0) goto L_0x000d;
    L_0x0007:
        r0 = new android.database.SQLException;
        r0.<init>();
        throw r0;
    L_0x000d:
        r1 = new java.lang.StringBuilder;
        r1.<init>();
        r2 = " select * from ";
        r1 = r1.append(r2);
        r1 = r1.append(r6);
        r2 = " order by _id asc LIMIT 1";
        r1 = r1.append(r2);
        r1 = r1.toString();
        r2 = r5.ॱ;	 Catch:{ SQLException -> 0x003a, all -> 0x0056 }
        r3 = 0;
        r0 = r2.rawQuery(r1, r3);	 Catch:{ SQLException -> 0x003a, all -> 0x0056 }
        r0.moveToNext();	 Catch:{ SQLException -> 0x003a }
        r1 = r0.getColumnNames();	 Catch:{ SQLException -> 0x003a }
        if (r0 == 0) goto L_0x0039;
    L_0x0036:
        r0.close();
    L_0x0039:
        return r1;
    L_0x003a:
        r1 = move-exception;
        r1 = o.bnc.ˎ;	 Catch:{ all -> 0x004c }
        r2 = "DownloadDbHelper";
        r3 = "DownloadDbHelper getColumnNames error [] ";
        r1.ˊ(r2, r3);	 Catch:{ all -> 0x004c }
        r1 = new android.database.SQLException;	 Catch:{ all -> 0x004c }
        r2 = "getColumnNames error []";
        r1.<init>(r2);	 Catch:{ all -> 0x004c }
        throw r1;	 Catch:{ all -> 0x004c }
    L_0x004c:
        r1 = move-exception;
        r4 = r1;
        r1 = r0;
        r0 = r4;
    L_0x0050:
        if (r1 == 0) goto L_0x0055;
    L_0x0052:
        r1.close();
    L_0x0055:
        throw r0;
    L_0x0056:
        r1 = move-exception;
        r4 = r1;
        r1 = r0;
        r0 = r4;
        goto L_0x0050;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.bnn.ॱॱ(java.lang.String):java.lang.String[]");
    }
}
